from django.db import models

class UserWebpage(models.Model):
    """
    用户上传的网页内容存储模型
    """
    id = models.AutoField(primary_key=True)
    user = models.CharField(
        max_length=255,
        verbose_name="用户"
    )
    content = models.TextField(
        verbose_name="网页内容"
    )
    
    class Meta:
        verbose_name = "用户网页"
        verbose_name_plural = "用户网页"
        db_table = 'myapp02_user_webpage'
    
    def __str__(self):
        return f"{self.user} - 网页内容"
    
    def get_content_preview(self, length=100):
        """获取内容预览"""
        if len(self.content) > length:
            return self.content[:length] + "..."
        return self.content
